package com.keste.ojt1.model.task6.syalla.entity;

import java.text.SimpleDateFormat;

import oracle.jbo.AttributeList;
import oracle.jbo.Key;
import oracle.jbo.Row;
import oracle.jbo.RowSet;
import oracle.jbo.domain.Date;
import oracle.jbo.domain.Number;
import oracle.jbo.server.AttributeDefImpl;
import oracle.jbo.server.EntityDefImpl;
import oracle.jbo.server.EntityImpl;
import oracle.jbo.server.SequenceImpl;

import weblogic.jms.utils.Simple;
// ---------------------------------------------------------------------
// ---    File generated by Oracle ADF Business Components Design Time.
// ---    Thu Jul 07 13:54:48 IST 2011
// ---    Custom code may be added to this class.
// ---    Warning: Do not modify method signatures of generated methods.
// ---------------------------------------------------------------------
public class LocationEOImpl extends EntityImpl {
    private static EntityDefImpl mDefinitionObject;

    /**
     * Validation method for UpdatedDate.
     */
    public boolean validateUpdatedDate(Date updateddate) {
        RowSet locAcc=getLocationVAcc();
        locAcc.executeQuery();
        Date oldDate = null;
        Row currRow = locAcc.first();
        if(currRow != null){
              oldDate = (Date)currRow.getAttribute("UpdatedDate");
            }
            // compareTo(Number n) 
            // Returns -1 if NUMBER is less than n, 0 if NUMBER and n are equal (==), 1 if NUMBER is greater than n.
            //System.out.println("the val is: "+ salary.compareTo(sal));
            if(updateddate.compareTo(oldDate) != -1){
              return false;
            }else{
               return true;
    }
    }
    /**
     * AttributesEnum: generated enum for identifying attributes and accessors. Do not modify.
     */
    public enum AttributesEnum {
        LocationId {
            public Object get(LocationEOImpl obj) {
                return obj.getLocationId();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setLocationId((Number)value);
            }
        }
        ,
        Address1 {
            public Object get(LocationEOImpl obj) {
                return obj.getAddress1();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setAddress1((String)value);
            }
        }
        ,
        Address2 {
            public Object get(LocationEOImpl obj) {
                return obj.getAddress2();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setAddress2((String)value);
            }
        }
        ,
        City {
            public Object get(LocationEOImpl obj) {
                return obj.getCity();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setCity((String)value);
            }
        }
        ,
        State {
            public Object get(LocationEOImpl obj) {
                return obj.getState();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setState((String)value);
            }
        }
        ,
        Country {
            public Object get(LocationEOImpl obj) {
                return obj.getCountry();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setCountry((String)value);
            }
        }
        ,
        PostalCode {
            public Object get(LocationEOImpl obj) {
                return obj.getPostalCode();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setPostalCode((String)value);
            }
        }
        ,
        CreationDate {
            public Object get(LocationEOImpl obj) {
                return obj.getCreationDate();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ,
        CreatedBy {
            public Object get(LocationEOImpl obj) {
                return obj.getCreatedBy();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ,
        UpdatedDate {
            public Object get(LocationEOImpl obj) {
                return obj.getUpdatedDate();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ,
        UpdatedBy {
            public Object get(LocationEOImpl obj) {
                return obj.getUpdatedBy();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ,
        ObjectVersionNo {
            public Object get(LocationEOImpl obj) {
                return obj.getObjectVersionNo();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ,
        StateVOAcc {
            public Object get(LocationEOImpl obj) {
                return obj.getStateVOAcc();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ,
        CityVOAcc {
            public Object get(LocationEOImpl obj) {
                return obj.getCityVOAcc();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ,
        LocationVAcc {
            public Object get(LocationEOImpl obj) {
                return obj.getLocationVAcc();
            }

            public void put(LocationEOImpl obj, Object value) {
                obj.setAttributeInternal(index(), value);
            }
        }
        ;
        private static AttributesEnum[] vals = null;
        private static int firstIndex = 0;

        public abstract Object get(LocationEOImpl object);

        public abstract void put(LocationEOImpl object, Object value);

        public int index() {
            return AttributesEnum.firstIndex() + ordinal();
        }

        public static int firstIndex() {
            return firstIndex;
        }

        public static int count() {
            return AttributesEnum.firstIndex() + AttributesEnum.staticValues().length;
        }

        public static AttributesEnum[] staticValues() {
            if (vals == null) {
                vals = AttributesEnum.values();
            }
            return vals;
        }
    }


    public static final int LOCATIONID = AttributesEnum.LocationId.index();
    public static final int ADDRESS1 = AttributesEnum.Address1.index();
    public static final int ADDRESS2 = AttributesEnum.Address2.index();
    public static final int CITY = AttributesEnum.City.index();
    public static final int STATE = AttributesEnum.State.index();
    public static final int COUNTRY = AttributesEnum.Country.index();
    public static final int POSTALCODE = AttributesEnum.PostalCode.index();
    public static final int CREATIONDATE = AttributesEnum.CreationDate.index();
    public static final int CREATEDBY = AttributesEnum.CreatedBy.index();
    public static final int UPDATEDDATE = AttributesEnum.UpdatedDate.index();
    public static final int UPDATEDBY = AttributesEnum.UpdatedBy.index();
    public static final int OBJECTVERSIONNO = AttributesEnum.ObjectVersionNo.index();
    public static final int STATEVOACC = AttributesEnum.StateVOAcc.index();
    public static final int CITYVOACC = AttributesEnum.CityVOAcc.index();
    public static final int LOCATIONVACC = AttributesEnum.LocationVAcc.index();

    /**
     * This is the default constructor (do not remove).
     */
    public LocationEOImpl() {
    }


    /**
     * @return the definition object for this instance class.
     */
    public static synchronized EntityDefImpl getDefinitionObject() {
        if (mDefinitionObject == null) {
            mDefinitionObject = EntityDefImpl.findDefObject("com.keste.ojt1.model.task6.syalla.entity.LocationEO");
        }
        return mDefinitionObject;
    }

    /**
     * Gets the attribute value for LocationId, using the alias name LocationId.
     * @return the LocationId
     */
    public Number getLocationId() {
        return (Number)getAttributeInternal(LOCATIONID);
    }

    /**
     * Sets <code>value</code> as the attribute value for LocationId.
     * @param value value to set the LocationId
     */
    public void setLocationId(Number value) {
        setAttributeInternal(LOCATIONID, value);
    }

    /**
     * Gets the attribute value for Address1, using the alias name Address1.
     * @return the Address1
     */
    public String getAddress1() {
        return (String)getAttributeInternal(ADDRESS1);
    }

    /**
     * Sets <code>value</code> as the attribute value for Address1.
     * @param value value to set the Address1
     */
    public void setAddress1(String value) {
        setAttributeInternal(ADDRESS1, value);
    }

    /**
     * Gets the attribute value for Address2, using the alias name Address2.
     * @return the Address2
     */
    public String getAddress2() {
        return (String)getAttributeInternal(ADDRESS2);
    }

    /**
     * Sets <code>value</code> as the attribute value for Address2.
     * @param value value to set the Address2
     */
    public void setAddress2(String value) {
        setAttributeInternal(ADDRESS2, value);
    }

    /**
     * Gets the attribute value for City, using the alias name City.
     * @return the City
     */
    public String getCity() {
        return (String)getAttributeInternal(CITY);
    }

    /**
     * Sets <code>value</code> as the attribute value for City.
     * @param value value to set the City
     */
    public void setCity(String value) {
        setAttributeInternal(CITY, value);
    }

    /**
     * Gets the attribute value for State, using the alias name State.
     * @return the State
     */
    public String getState() {
        return (String)getAttributeInternal(STATE);
    }

    /**
     * Sets <code>value</code> as the attribute value for State.
     * @param value value to set the State
     */
    public void setState(String value) {
        setAttributeInternal(STATE, value);
    }

    /**
     * Gets the attribute value for Country, using the alias name Country.
     * @return the Country
     */
    public String getCountry() {
        return (String)getAttributeInternal(COUNTRY);
    }

    /**
     * Sets <code>value</code> as the attribute value for Country.
     * @param value value to set the Country
     */
    public void setCountry(String value) {
        setAttributeInternal(COUNTRY, value);
    }

    /**
     * Gets the attribute value for PostalCode, using the alias name PostalCode.
     * @return the PostalCode
     */
    public String getPostalCode() {
        return (String)getAttributeInternal(POSTALCODE);
    }

    /**
     * Sets <code>value</code> as the attribute value for PostalCode.
     * @param value value to set the PostalCode
     */
    public void setPostalCode(String value) {
        setAttributeInternal(POSTALCODE, value);
    }

    /**
     * Gets the attribute value for CreationDate, using the alias name CreationDate.
     * @return the CreationDate
     */
    public Date getCreationDate() {
        return (Date)getAttributeInternal(CREATIONDATE);
    }

    /**
     * Gets the attribute value for CreatedBy, using the alias name CreatedBy.
     * @return the CreatedBy
     */
    public String getCreatedBy() {
        return (String)getAttributeInternal(CREATEDBY);
    }

    /**
     * Gets the attribute value for UpdatedDate, using the alias name UpdatedDate.
     * @return the UpdatedDate
     */
    public Date getUpdatedDate() {
        return (Date)getAttributeInternal(UPDATEDDATE);
    }

    /**
     * Gets the attribute value for UpdatedBy, using the alias name UpdatedBy.
     * @return the UpdatedBy
     */
    public String getUpdatedBy() {
        return (String)getAttributeInternal(UPDATEDBY);
    }

    /**
     * Gets the attribute value for ObjectVersionNo, using the alias name ObjectVersionNo.
     * @return the ObjectVersionNo
     */
    public Number getObjectVersionNo() {
        return (Number)getAttributeInternal(OBJECTVERSIONNO);
    }

    /**
     * getAttrInvokeAccessor: generated method. Do not modify.
     * @param index the index identifying the attribute
     * @param attrDef the attribute

     * @return the attribute value
     * @throws Exception
     */
    protected Object getAttrInvokeAccessor(int index,
                                           AttributeDefImpl attrDef) throws Exception {
        if ((index >= AttributesEnum.firstIndex()) && (index < AttributesEnum.count())) {
            return AttributesEnum.staticValues()[index - AttributesEnum.firstIndex()].get(this);
        }
        return super.getAttrInvokeAccessor(index, attrDef);
    }

    /**
     * setAttrInvokeAccessor: generated method. Do not modify.
     * @param index the index identifying the attribute
     * @param value the value to assign to the attribute
     * @param attrDef the attribute

     * @throws Exception
     */
    protected void setAttrInvokeAccessor(int index, Object value,
                                         AttributeDefImpl attrDef) throws Exception {
        if ((index >= AttributesEnum.firstIndex()) && (index < AttributesEnum.count())) {
            AttributesEnum.staticValues()[index - AttributesEnum.firstIndex()].put(this, value);
            return;
        }
        super.setAttrInvokeAccessor(index, value, attrDef);
    }

    /**
     * Gets the view accessor <code>RowSet</code> StateVOAcc.
     */
    public RowSet getStateVOAcc() {
        return (RowSet)getAttributeInternal(STATEVOACC);
    }

    /**
     * Gets the view accessor <code>RowSet</code> CityVOAcc.
     */
    public RowSet getCityVOAcc() {
        return (RowSet)getAttributeInternal(CITYVOACC);
    }


    /**
     * Gets the view accessor <code>RowSet</code> LocationVAcc.
     */
    public RowSet getLocationVAcc() {
        return (RowSet)getAttributeInternal(LOCATIONVACC);
    }

    /**
     * Validation method for LocationEO.
     */
    public boolean validateLocationUpdateDate() {
     // RowSet locAcc=getLocationVAcc();
     // locAcc.executeQuery();
      //Date oldDate = null;
     // Row currRow = locAcc.first();
        Date old;
        old = (Date)getPostedAttribute(this.UPDATEDDATE);
        if(old==null){
            return true;
            }
        java.sql.Date dataVal = old.dateValue();
        int i=dataVal.compareTo(Date.getCurrentDate().dateValue());
            
          if(i < 0){
            return true;
          }else{
             return false;
      }
    }

    /**
     * @param locationId key constituent

     * @return a Key object based on given key constituents.
     */
    public static Key createPrimaryKey(Number locationId) {
        return new Key(new Object[]{locationId});
    }

    /**
     * Add attribute defaulting logic in this method.
     * @param attributeList list of attribute names/values to initialize the row
     */
    protected void create(AttributeList attributeList) {
        super.create(attributeList);
      SequenceImpl seq = new SequenceImpl("LOCATION_S", this.getDBTransaction());
      setLocationId(new Number(seq.getSequenceNumber()));
    }
}
